
<div class="current_location">
    <ul>
        <li><a>当前位置：</a></li>
        <li><a>分类管理</a></li>
        <li> > <a><?php if(!empty($view_data['good_category_info'])): ?>编辑分类<?php else: ?>新增分类<?php endif ?></a></li>
    </ul>
</div>

<form id="add_category_form" method="post" action="<?php echo $view_data['save_url']; ?>"  onsubmit="return save_category();">
    <?php if(!empty($view_data['good_category_info'])): ?>
        <input type="hidden" name="id" value="<?php echo $view_data['good_category_info']['id']; ?>" />
    <?php endif ?>

    <div class="form_content">
        <div class="unit">
            <label>名称：</label>
            <input type="text"  name="name" />
        </div>

        <div class="unit">
            <label>上级：</label>
            <select name="parent_id">
                <option value="0">顶级</option>

                <?php foreach ($view_data['all_category_list'] as $category): ?>
                <option value="<?php echo $category['id']; ?>" <?php if(!empty($view_data['good_category_info']) && $category['id'] === $view_data['good_category_info']['parent_id']): echo 'selected="selected"'; endif ?> >
                    <?php
                    for($i = 1; $i <= $category['level']; $i++){
                        echo '&nbsp;&nbsp;';
                    }
                    ?>
                    <?php echo $category['name']; ?>
                </option>
                <?php endforeach ?>
            </select>
        </div>

        <div class="unit">
            <label>排序：</label>
            <input type="text" name="order" />
        </div>

        <div class="unit">
            <label>状态：</label>
            <select name="status">
                <option value="1">启用</option>
                <option value="0">禁用</option>
            </select>
        </div>

        <div class="unit">
            <label></label>
            <input class="input_submit" type="submit" value="提交" />
        </div>
    </div>
</form>

<script type="text/javascript">
    <?php if(!empty($view_data['good_category_info'])): ?>
    $(':input[name="name"]').val('<?php echo $view_data['good_category_info']['name']; ?>');
    $(':input[name="order"]').val('<?php echo $view_data['good_category_info']['order']; ?>');
    $(':input[name="status"]').val('<?php echo $view_data['good_category_info']['status']; ?>');
    <?php /* $(':input[name="description"]').val('<?php echo $view_data['good_category_info']['description']; ?>'); */?>
    <?php endif ?>

    function save_category(){
        $.ajax({
            type: 'POST',
            url: "<?php echo $view_data['save_url']; ?>",
            data: $('#add_category_form').serialize(),
            dataType: 'json',
            success: function(rdata){
                if(rdata.status <= 0){
                    alert(rdata.message);
                    set_error_detail_info_by_rdata(rdata);
                }else{
                    alert(rdata.message);
                    window.top.location.replace('<?php echo $view_data['index_url']; ?>');
                }

                return false;
            }
        });

        return false;
    }
</script>